package com.isczy.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.isczy.eduservice.entity.EduCourse;
import com.isczy.eduservice.entity.EduTeacher;
import com.isczy.eduservice.service.EduCourseService;
import com.isczy.eduservice.service.EduTeacherService;
import com.isczy.servicebase.exceptionHandler.MyException;
import com.isczy.utils.DataResult;
import com.isczy.utils.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/***
 * ***************************************
 * 功能描述:前台
 * @author create: TODO 人员:【ChangZiYang】类型:【新增方法】日期:【2021-01-13 10:58】
 * @author modify:
 */
@RestController
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {

    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduTeacherService teacherService;

    /***
     * ***************************************
     * 功能描述:查询前8条热门课程，查询前4条名师
     * @param
     * @return {@link DataResult}
     * @author create: TODO 人员:【ChangZiYang】类型:【新增方法】日期:【2021-01-13 11:00】
     * @author modify:
     */
    @GetMapping("index")
    public DataResult index() {
        try {

            List<EduCourse> courseList = courseService.getHotCourseList();

            List<EduTeacher> teacherList = teacherService.getHotTeacherList();

            return DataResult.builder()
                    .data("eduList",courseList)
                    .data("teacherList",teacherList)
                    .successBuild();
        }catch (Exception e){
            throw MyException.builder()
                    .exception(e)
                    .code(ResultCode.ERROR)
                    .className(getClass().getName())
                    .methodName(Thread.currentThread().getStackTrace()[1].getMethodName())
                    .message("查询前8条热门课程，查询前4条名师失败")
                    .build();
        }
    }

}
